package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaWorkerSettleScale;
import com.ruoyi.system.service.IJiajiaWorkerSettleScaleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社工结算比例阶梯Controller
 * 
 * @author ruoyi
 * @date 2024-05-08
 */
@Controller
@RequestMapping("/jiajia/settle/scale")
public class JiajiaWorkerSettleScaleController extends BaseController
{
    private String prefix = "jiajia/settleScale";

    @Autowired
    private IJiajiaWorkerSettleScaleService jiajiaWorkerSettleScaleService;

    @RequiresPermissions("system:scale:view")
    @GetMapping()
    public String scale()
    {
        return prefix + "/scale";
    }

    /**
     * 查询社工结算比例阶梯列表
     */
    @RequiresPermissions("system:scale:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaWorkerSettleScale jiajiaWorkerSettleScale)
    {
        startPage();
        List<JiajiaWorkerSettleScale> list = jiajiaWorkerSettleScaleService.selectJiajiaWorkerSettleScaleList(jiajiaWorkerSettleScale);
        return getDataTable(list);
    }

    /**
     * 导出社工结算比例阶梯列表
     */
    @RequiresPermissions("system:scale:export")
    @Log(title = "社工结算比例阶梯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaWorkerSettleScale jiajiaWorkerSettleScale)
    {
        List<JiajiaWorkerSettleScale> list = jiajiaWorkerSettleScaleService.selectJiajiaWorkerSettleScaleList(jiajiaWorkerSettleScale);
        ExcelUtil<JiajiaWorkerSettleScale> util = new ExcelUtil<JiajiaWorkerSettleScale>(JiajiaWorkerSettleScale.class);
        return util.exportExcel(list, "社工结算比例阶梯数据");
    }

    /**
     * 新增社工结算比例阶梯
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社工结算比例阶梯
     */
    @RequiresPermissions("system:scale:add")
    @Log(title = "社工结算比例阶梯", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaWorkerSettleScale jiajiaWorkerSettleScale)
    {
        return toAjax(jiajiaWorkerSettleScaleService.insertJiajiaWorkerSettleScale(jiajiaWorkerSettleScale));
    }

    /**
     * 修改社工结算比例阶梯
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaWorkerSettleScale jiajiaWorkerSettleScale = jiajiaWorkerSettleScaleService.selectJiajiaWorkerSettleScaleById(id);
        mmap.put("jiajiaWorkerSettleScale", jiajiaWorkerSettleScale);
        return prefix + "/edit";
    }

    /**
     * 修改保存社工结算比例阶梯
     */
    @RequiresPermissions("system:scale:edit")
    @Log(title = "社工结算比例阶梯", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaWorkerSettleScale jiajiaWorkerSettleScale)
    {
        return toAjax(jiajiaWorkerSettleScaleService.updateJiajiaWorkerSettleScale(jiajiaWorkerSettleScale));
    }

    /**
     * 删除社工结算比例阶梯
     */
    @RequiresPermissions("system:scale:remove")
    @Log(title = "社工结算比例阶梯", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaWorkerSettleScaleService.deleteJiajiaWorkerSettleScaleByIds(ids));
    }
}
